﻿CREATE PROCEDURE [dbo].[yaf_eventlog_create](
                @UserID      INT,
                @Source      NVARCHAR(50),
                @Description NTEXT,
                @Type        INT)
AS
    BEGIN
        INSERT INTO dbo.yaf_EventLog
                   (UserID,
                    Source,
                    Description,
                    TYPE)
        VALUES     (@UserID,
                    @Source,
                    @Description,
                    @Type)
        -- delete entries older than 10 days
        DELETE FROM dbo.yaf_EventLog
        WHERE       EventTime + 10 < Getdate()
        -- or if there are more then 1000
        IF ((SELECT COUNT(* )
             FROM   yaf_eventlog) >= 1050)
        BEGIN
            DELETE FROM dbo.yaf_EventLog
            WHERE       EventLogID IN (SELECT   TOP 100 EventLogID
                           FROM     dbo.yaf_EventLog
                           ORDER BY EventTime)
        END
        
    END


